<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>登陆/注册</title>
  <script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.js"></script>
</head>

<body>
  <p>用户名：
    <input type="text" value="" id="user" />
  </p>
  <p>密码：
    <input type="password" value="" id="pass" />
  </p>
  <p>
    <input type="button" value="注册" id="reg_btn" />
    <input type="button" value="登录" id="login_btn" />
  </p>
</body>

</html>

<script>
  window.onload = function () {
    $(document).on('click', '#reg_btn', () => {
      let params = { act: 'reg', user: $("#user").val(), pass: $("#pass").val() }
      $.ajax({
        type: 'GET',
        url: '/user',
        data: params,
        dataType: 'json',
        success: function (data) {
          console.log(data)
          alert(data.msg)
        }
      })
    })
    $(document).on('click', '#login_btn', () => {
      let params = { act: 'login', user: $("#user").val(), pass: $("#pass").val() }
      $.ajax({
        type: 'GET',
        url: '/user',
        data: params,
        dataType: 'json',
        success: function (data) {
          console.log(data)
          alert(data.msg)
        }
      })
    })
  }
</script>